package com.example.pc.adaptivelandscapeandfagmentationvalues;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    private int orientation = Configuration.ORIENTATION_PORTRAIT;//屏幕方向
    private LeftFragment leftFragment;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //获取手机配置
        Configuration configuration = getResources().getConfiguration();
        //使用配置获取手机屏幕当前的方向
        orientation = configuration.orientation;
        if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
            Log.d(TAG, "onCreate: 横屏");
        } else if (orientation == Configuration.ORIENTATION_PORTRAIT) {
            Log.d(TAG, "onCreate: 竖屏");
        } else if (orientation == Configuration.ORIENTATION_UNDEFINED) {
            Log.d(TAG, "onCreate: 弹出框的Activity");
        }
        setContentView(R.layout.activity_main);
        initFragment(); }
    private void initFragment() {
        //获取管理器
        FragmentTransaction bt = getSupportFragmentManager().beginTransaction();
        leftFragment = new LeftFragment();
        //当前屏幕替换成左边碎片
        bt.replace(R.id.fl_left, leftFragment);
        //判断是否是横屏
        if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
            bt.replace(R.id.fl_right, new RightFragment(), "right");
        }
        bt.commit();
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();

    }
}